

$(function () {

    var c_url = "iifoxHandler/AgentStatusStatistics";
    var $table = $('#DataGrid');

    $table.lgbTable({

        url: c_url,
        dataBinder: {
            map: {

            },

            callback: function (data) {
                //if (data && data.success && data.oper === 'save'
                //    && data.data.UserName === $('#userDisplayName').attr('data-userName')) {
                //    $('#userDisplayName').text(data.data.DisplayName);
                //}
                //if (data && data.oper === 'create') {
                //    $('#userName').prop('readonly', false).removeClass("ignore");
                //}
                //else if (data && data.oper === 'edit') {
                //    $('#userName').prop('readonly', true).addClass("ignore");
                //}
            }
        },
        smartTable: {
            idField: "StatisticDate",
            sortName: "StatisticDate",
            sortOrder: "desc",
            queryParams: function (params) {
                return $.extend(params, {
                    AgentNo: $("#txt_AgentNo").val(),//座席
                    BeginDate: $("#txt_operate_start").val(), //开始日期
                    EndDate: $("#txt_operate_end").val(),//结束日期
                    CallerID: $("#txt_CallerID").val(),//主叫号
                    CalleeID: $("#txt_CalleeID").val(),//被叫号
                    CallDir: $("#txt_CallDir").val(),//呼叫方向
                });
            },           //传递参数（*）
            columns: [
                {
                    title: "日期", field: "Date", sortable: true, 
                },
                { title: "开始时间", field: "BeginTime", sortable: true, class: "text-center"  },
                { title: "结束时间", field: "EndTime", sortable: true, class: "text-center"  },
                { title: "主叫号", field: "CallerID", sortable: true, class: "text-center" },
                { title: "被叫号", field: "CalleeID", sortable: true, class: "text-center"  },
                { title: "状态", field: "Status", sortable: true, class: "text-center"},
                { title: "座席", field: "AgentNo", sortable: true, class: "text-center"  },
                { title: "分机", field: "PhoneNo", sortable: true, class: "text-center" },
                {
                    title: "状态持续时长", field: "StatisticTime", sortable: true,class: "text-center", formatter: function (value, row, index) {
                        return newDate(value);
                    }
                },
                { title: "小休理由/挂机原因", field: "parkcause", sortable: true },
                { title: "呼叫方向", field: "CallDir", sortable: true, class: "text-center" },
               
                { title: "随路数据", field: "PrivateData", sortable: true },
            ],
            editButtons: {
                events: {
                    'click': function (e, value, row, index) {
                        $table.bootstrapTable('uncheckAll');
                        $table.bootstrapTable('check', index);
                    }
                },
                formatter: function (value, row, index) {
                    var $this = this.clone();
                    if (row.IsReset === 0) {
                        $this.find('button.reset').remove();
                    }
                    return $this.html();
                }
            },
            exportOptions: {
                fileName: "座席状态",
                ignoreColumn: [0, 7]
            }
        }
    });
  
    
});

function newDate(value) { //将秒数转为时分秒 格式 HH:mm:ss
    value = parseInt(value); //去掉小数点后数据
    var data;
    if (value > -1) {
        var hour = Math.floor(value / 3600);//小时
        var min = Math.floor(value / 60) % 60;//分钟
        var sec = value % 60;
        if (hour < 10) {
            data = '0' + hour + ":";
        } else {
            data = hour + ":";
        }
        if (min < 10) { data += "0"; }
        data += min + ":";
        if (sec < 10) { data += "0"; }
        data += sec.toFixed(0);
    }
    return data;
}

